﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    public class LichThiProvider
    {
        public static List<LichThi> LayDanhSachLichThi()
        {
            var lst = new List<LichThi>();
            using (var context = new QLTTTHEntities())
            {
                var query = (from u in context.LichThis select u);

                foreach (var row in query)
                {
                    var lich = new LichThi();
                    lich.MaHV = row.MaHV;
                    lich.MaKyThi = row.MaKyThi;
                    lich.MaPhong = row.MaPhong;
                    lich.MaLichThi = row.MaLichThi;
                    lich.GioThi = row.GioThi;
                    lst.Add(lich);
                }
            }

            return lst;
        }



        public static int Themlichthi(LichThi lichthi)
        {
            int maLichThi = -1;
            try
            {
                using (var context = new QLTTTHEntities())
                {
                    context.LichThis.Add(lichthi);
                    context.SaveChanges();
                    maLichThi = lichthi.MaLichThi;
                }
            }
            catch
            {

            }
            return maLichThi;
        }




        public static bool XoaLichThi(int maLichThi)
        {
            try
            {
                using (var context = new QLTTTHEntities())
                {
                    var query = (from u in context.LichThis
                                 where u.MaLichThi.Equals(maLichThi)
                                 select u).First();

                    context.LichThis.Remove(query);
                    context.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }



        public static bool CapNhapLichThi(LichThi lichthi)
        {
            try
            {
                using (var context = new QLTTTHEntities())
                {
                    var query = (from u in context.LichThis
                                 where u.MaLichThi.Equals(lichthi.MaLichThi)
                                 select u).First();

                    query.MaKyThi = lichthi.MaKyThi;
                    query.MaHV = lichthi.MaHV;
                    query.MaPhong = lichthi.MaPhong;
                    query.GioThi = lichthi.GioThi;
                    context.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
